package algorithms.leaning.class17;

import common.util.MyUtil;

/**
 * 打印n层汉诺塔从最左边移动到最右边的全部过程
 * <p>
 * 进阶版，使用1个过程
 *
 * @author guichang
 * @date 2021/6/16
 */

@SuppressWarnings("all")
public class Code3_递归_汉诺塔2 {

    public static void main(String[] args) {
        hanoi(3);
    }

    public static void hanoi(int n) {
        process(n, "左", "右", "中");
    }

    private static void process(int n, String from, String to, String other) {
        if (n == 1) {
            MyUtil.printf("移动{}从{}到{}", n, from, to);
            return;
        }
        process(n - 1, from, other, to);
        MyUtil.printf("移动{}从{}到{}", n, from, to);
        process(n - 1, other, to, from);
    }

}